//
//  LSTabBarController.m
//  5.TabBar中间按钮
//
//  Created by 梁森 on 2020/7/13.
//  Copyright © 2020 梁森. All rights reserved.
//

#import "LSTabBarController.h"

#import "LSLeftViewController.h"
#import "LSRightViewController.h"
#import "LSTabBar.h"

@interface LSTabBarController ()

@end

@implementation LSTabBarController

+ (void)load{
    NSDictionary *attribute = @{NSForegroundColorAttributeName:[UIColor redColor]};
    NSDictionary *attributeSelecte = @{NSForegroundColorAttributeName:[UIColor blueColor]};
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[[LSTabBarController class]]];
    [item setTitleTextAttributes:attribute forState:UIControlStateNormal];
    [item setTitleTextAttributes:attributeSelecte forState:UIControlStateSelected];
    [[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
    [UITabBar appearance].translucent = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setChildVCs];
}

- (void)setChildVCs{
    [self addChildViewController:[LSLeftViewController new] withTitle:@"左" image:@"tabbar_icon_home_selected" selectImage:@"tabbar_icon_home_default"];
    [self addChildViewController:[LSRightViewController new] withTitle:@"右" image:@"tabbar_icon_user_selected" selectImage:@"tabbar_icon_user_default"];
    
    LSTabBar * tabBar = [[LSTabBar alloc] initWithImage:[UIImage imageNamed:@"tabbar_icon_repair_bg_default"] andTitle:@"中间字"];
    [self setValue:tabBar forKey:@"tabBar"];
}

- (void)addChildViewController:(UIViewController *)childController withTitle:(NSString *)title image:(NSString *)image selectImage:(NSString *)selectImage{
    childController.title = title;
    childController.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childController.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self addChildViewController:childController];
}


@end
